package com.MusicWeb.servlet;

import com.MusicWeb.service.CollectionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/CollectionAdd")
//todo: 收藏音乐接口
//http://localhost:8080/CollectionAdd?music_id?&user_id=?
public class CollectionServlet extends HttpServlet {
    CollectionService collectionService = new CollectionService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer mid = Integer.parseInt(req.getParameter("music_id"));
        Integer uid = Integer.parseInt(req.getParameter("user_id"));
        int res = collectionService.CollectionAdd(mid, uid);
        resp.getWriter().print(res);
//        if (res != -1) {
//            req.getSession().setAttribute("msg", "收藏成功");
//            resp.sendRedirect(req.getContextPath() + "/FunctionPage/MusicHome.jsp");
//        }else {
//            req.getSession().setAttribute("msg", "收藏失败");
//            resp.sendRedirect(req.getContextPath() + "/FunctionPage/MusicHome.jsp");
//        }
    }
}
